home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / batch / library / batutl2 / tune.asm < prev    next >
Assembly Source File  |  1988-04-20  |  4KB  |  175 lines

  1. TITLE    TUNE    6-10-84    [4-19-88]
  2. ;Toad Hall Disassembly, tweak
  3.  
  4. LF    EQU    0AH
  5. CR    EQU    0DH
  6. UNK_FREQ equ    0FFFEH
  7. TUNE_END equ    0FFFFH
  8.  
  9. ;
  10. ;INITIAL VALUES :    CS:IP    0000:0100
  11. ;            SS:SP    0000:FFFF
  12. CodeSeg    SEGMENT
  13.     ASSUME DS:CodeSeg,SS:CodeSeg,CS:CodeSeg,ES:CodeSeg
  14.     ORG    100H
  15.  
  16. Tune    proc    near
  17.     JMP    Start
  18.  
  19. ;Table of tune data addresses
  20. tuneTable    label    word
  21.     DW    tune1,tune2,tune3,tune4,tune5
  22.     DW    tune6,tune7,tune8,tune9
  23.  
  24. ;words are (1) frequency lsb & msb, (2) duration
  25. tune1    DW    05DCH,0008H
  26.     dw    053CH,0008H
  27.     dw    06A4H,0008H
  28.     dw    0D48H,0008H
  29.     dw    08FCH,0010H
  30.     DW    TUNE_END
  31.  
  32. tune2    DW    05DCH,0008H
  33.     dw    053CH,0008H
  34.     dw    06A4H,0008H
  35.     dw    08FCH,0008H
  36.     dw    0474H,0010H
  37.     DW    TUNE_END
  38.  
  39. tune3    DW    05DCH,0008H
  40.     dw    053CH,0008H
  41.     dw    06A4H,0008H
  42.     DW    0D48H,0008H
  43.     dw    08FCH,0008H
  44.     DW    08FCH,0008H
  45.     dw    08FCH,0008H
  46.     dw    0D48H,0008H
  47.     dw    08FCH,0008H
  48.     dw    08FCH,0008H
  49.     DW    08FCH,0008H
  50.     dw    0FA0H,0010H
  51.     dw    TUNE_END
  52.  
  53. tune4    DW    0FA0H,0010H
  54.     dw    0FA0H,0010H
  55.     dw    0FA0H,0008H
  56.     dw    0FA0H,0010H
  57.     dw    0D48H,0010H
  58.     DW    0DACH,0008H
  59.     dw    0DACH,0010H
  60.     dw    0FA0H,0008H
  61.     dw    0FA0H,0010H
  62.     dw    1068H,0008H
  63.     DW    0FA0H,0010H
  64.     dw    TUNE_END
  65.  
  66. tune5    DW    07D0H,0008H
  67.     dw    0708H,0008H
  68.     dw    0640H,0008H
  69.     dw    053CH,0010H
  70.     dw    0640H,0008H
  71.     DW    053CH,0010H
  72.     dw    TUNE_END
  73.  
  74. tune6    DW    0708H,0008H
  75.     dw    0640H,0010H
  76.     dw    053CH,0010H
  77.     dw    0640H,0008H
  78.     dw    0708H,0008H
  79.     DW    0640H,0008H
  80.     dw    07D0H,0020H
  81.     dw    UNK_FREQ,0008H
  82.     dw    03E8H,0008H
  83. tune7    label    word
  84. tune8    label    word
  85. tune9    label    word
  86.     dw    TUNE_END
  87.  
  88. ;If you want tunes 7 through 9:
  89. ; Add their data here.
  90. ; Rem out the appropriate bogus "tune%" label(s) above.
  91. ; Insure each tune ends with 0FFFFH
  92.  
  93. ;L01E1      L0113 DI
  94. ;tune7    DW    TUNE_END
  95. ;tune8    DW    TUNE_END
  96. ;tune9    DW    TUNE_END
  97.  
  98. ;If you know you have a fast processor, you can fiddle this
  99. ;delay constant appropriately (or just use the cmd line slow..fast
  100. ;adjuster).
  101.  
  102. delayConst    dw    2000H        ;delay constant
  103.  
  104. Start:
  105.     cld                ;insure fwd
  106.     MOV    DI,65H            ;DOS PSP cmd line?
  107. ;original used BL throughout .. but AX/AL is faster...
  108.     MOV    al,[DI]            ;snarf PSP data
  109.     CMP    al,20H            ;any slow..fast modifier?
  110.     JZ    L0202            ;nope, no delay modifier
  111.      AND    al,0FH            ;mask the delay to 0..15
  112.      MOV    CL,4
  113.      SHL    al,CL            ;*16
  114.      MOV    byte ptr delayConst+1,al    ;new delay constant msb
  115. L0202:    MOV    DI,5DH            ;cmd line start
  116. CmdLup:
  117.     MOV    al,[DI]            ;snarf cmd line char
  118.     CMP    al,'1'
  119.     JB    Die_224            ; illegal
  120.     CMP    al,'9'            ; illegal
  121.     JA    Die_224
  122.     AND    al,0FH            ;mask to 0..15
  123.     DEC    al            ;adjust
  124.     SHL    al,1            ; * 2 for words
  125.     XOR    ah,ah            ;clear msb
  126.     mov    bx,ax            ;into BX for offset
  127.     MOV    SI,[BX+tuneTable]    ;get this tune's starting offset
  128.     CALL    Play_Tune        ;play the tune
  129.     INC    DI            ;bump cmd line ptr
  130.     JMP    SHORT    CmdLup        ; and continue processing cmd line
  131.  
  132. Die_224:
  133.     mov    ax,4C00H        ;terminate process
  134.     int    21H
  135. Tune    endp
  136.  
  137.  
  138. ;L0225      L021E CC  L025E CJ
  139. Play_Tune    proc    near
  140.     LODSW                ;get tune data (note frequency)
  141.     CMP    AX,TUNE_END        ; done?
  142.     JZ    Tune_Done        ; yep
  143.     MOV    DX,AX            ;remember it here
  144.     MOV    AL,0B6H            ;prepare sound register
  145.     OUT    43H,AL
  146.     MOV    AL,dl            ;sound data lsb
  147.     OUT    42H,AL
  148.     MOV    AL,dh            ;sound data msb
  149.     OUT    42H,AL
  150.     IN    AL,61H            ;get sound reg status
  151.     MOV    BH,AL            ;save in BH for output later
  152.     CMP    DX,UNK_FREQ        ;was last data this?
  153.     JZ    Skp24A            ; yep, don't bother sound reg
  154.      OR    AL,3
  155.      OUT    61H,AL            ;fiddle sound reg somehow
  156. Skp24A:    LODSW                ;snarf next tune data (note length)
  157. Lup24B:    MOV    CX,delayConst        ;delay constant
  158. Delay24F:
  159.     LOOP    Delay24F        ;delay a bit
  160.     DEC    AX            ;decrement note length counter
  161.     JNZ    Lup24B            ;keep playing
  162.     MOV    AL,BH            ;get that status back
  163.     OUT    61H,AL            ;sound off ?
  164.     MOV    CX,delayConst        ;delay constant
  165. Delay25C:
  166.     LOOP    Delay25C
  167.     JMP    SHORT    Play_Tune    ;loop until tune is done
  168.  
  169. Tune_Done:
  170.     RET
  171. Play_Tune    endp
  172.  
  173. CodeSeg    ENDS
  174.     END    Tune
  175.